from com.UseCOMMAND import UseCOMMAND


class AcquireLinSymInfo(UseCOMMAND):
    def __init__(self, hostname, port, name, password):
        # 调用父类的构造器
        super(AcquireLinSymInfo, self).__init__(hostname, port, name, password)

    # 获取全部内存信息
    def get_allRAMemory(self):
        mem_stdout_info = self.get_message_line("cat /proc/meminfo")
        memory_dic = {}
        for line in mem_stdout_info:
            # 去除多余的冒号，并且把他们分割
            ls_line = line.replace(":", "").split()
            memory_dic[ls_line[0]] = round(float(ls_line[1]) / 1024, 2)
        return memory_dic

    # 获取CPU的全部信息
    def get_allCPUInformation(self):
        cpu_stdout_info = self.get_message_line('cat /proc/cpuinfo')
        cpu_dic = {}
        for line in cpu_stdout_info:
            # 用冒号分割，去除多余的\n
            ls_line = line.strip('\n').split(':')
            # 去除第一个值的\t
            ls_line[0] = ls_line[0].strip('\t')
            # 由于上一步的处理 在获取key值的时候发现 有列表只有一个元素 且为 ''  故判断  否则会报错：列表下标溢出
            if ls_line[0] != '':
                cpu_dic[ls_line[0]] = ls_line[1]
        return cpu_dic

    # 负载均衡
    def get_loadBalance(self):
        loadBalance_stdout_info = self.get_message_line('cat /proc/loadavg')[0].split()
        loadBalance_dic = {'bef_5min_loadavgs': loadBalance_stdout_info[0],
                           'bef_10min_loadavgs': loadBalance_stdout_info[1],
                           'bef_15min_loadavgs': loadBalance_stdout_info[2],
                           'usingThread_and_totalThread': loadBalance_stdout_info[3],
                           'recently_usingThread_id': loadBalance_stdout_info[4]
                           }
        return loadBalance_dic

    # 获取磁盘空间使用量
    def get_diskSpace(self):
        pass
